<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>小说列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <!--  <link rel="stylesheet" href="/static/layuiadmin/style/template.css" media="all">-->

    <style>
        .text-c{
            text-align: center !important;
        }

        .layui-card span[lay-separator] {
            margin: 0 10px;
            color: #999;
            font-weight: bold;
        }

        #LAY-component-grid-stack .page {
            display: flex;
            justify-content: center;
            flex-direction: column;
            text-align: center;
            height: 120px;
        }

        table em {
            font-style: normal;
            margin-left: 5px;
        }

        .caller-main p {
            padding: 9px 0;
        }

        .layui-layer-demo .layui-layer-title {
            border: none;
            background-color: #333;
            color: #fff;
        }
    </style>
</head>

<body>
<div class="layui-fluid" id="LAY-component-grid-stack">

    <div class="layui-row layui-col-space5">
        <div class="layui-col-md12" style="min-width: 880px;">
            <div class="layui-card">
                <div class="layui-card-header">
                    条件检索
                </div>
                <div class="layui-card-body" style="text-align: left;padding-top: 30px;">

                    <form class="layui-form" action="" method="get">
                        <input type="hidden" name="freq_id" value="{$freq.id}">
                        <input type="hidden" name="class_id" value="{$class.id}">
                        <input type="hidden" name="update_status" value="{$update_status}">
                        <input type="hidden" name="words_type" value="{$words_type}">
                        <input type="hidden" name="label_id" value="{$label_id}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">频道：</label>
                            <div class="layui-input-block">
                                <div class="layui-btn-container">
                                    <a type="button" href="/spread/novels?class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if !$freq}{else /}layui-btn-primary{/if}">不限</a>
                                    {foreach $freqArr as $v}
                                    <a type="button" href="/spread/novels?freq_id={$v.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $freq.id == $v.id}{else /}layui-btn-primary{/if}">{$v.name}</a>
                                    {/foreach}
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">分类：</label>
                            <div class="layui-input-block">
                                <div class="layui-btn-container">
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&update_status={$update_status}&words_type={$words_type}&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if !$class}{else /}layui-btn-primary{/if}">不限</a>
                                    {foreach $classArr as $v}
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$v.id}&update_status={$update_status}&words_type={$words_type}&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $class.id == $v.id}{else /}layui-btn-primary{/if} ">{$v.name}</a>
                                    {/foreach}
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">状态：</label>
                            <div class="layui-input-block">
                                <div class="layui-btn-container">
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&words_type={$words_type}&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $update_status === ''}{else /}layui-btn-primary{/if}">不限</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status=0&words_type={$words_type}&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $update_status === 0}{else /}layui-btn-primary{/if}">连载</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status=1&words_type={$words_type}&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $update_status === 1}{else /}layui-btn-primary{/if}">完结</a>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">字数：</label>
                            <div class="layui-input-block">
                                <div class="layui-btn-container">
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type=0&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $words_type == 0}{else /}layui-btn-primary{/if}">不限</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type=1&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $words_type == 1}{else /}layui-btn-primary{/if} ">30万字以下</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type=2&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $words_type == 2}{else /}layui-btn-primary{/if} ">30-50万字</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type=3&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $words_type == 3}{else /}layui-btn-primary{/if} ">50-100万字</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type=4&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $words_type == 4}{else /}layui-btn-primary{/if} ">100-200万字</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type=5&scale={$scale}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $words_type == 5}{else /}layui-btn-primary{/if} ">200万字以上</a>
                                </div>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">评级：</label>
                            <div class="layui-input-block">
                                <div class="layui-btn-container">
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&label_id={$label_id}" class="layui-btn layui-btn-sm {if $scale === ''}{else /}layui-btn-primary{/if}">不限</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale=S&label_id={$label_id}" class="layui-btn layui-btn-sm {if $scale === 'S'}{else /}layui-btn-primary{/if}">S</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale=A&label_id={$label_id}" class="layui-btn layui-btn-sm {if $scale === 'A'}{else /}layui-btn-primary{/if}">A</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale=B&label_id={$label_id}" class="layui-btn layui-btn-sm {if $scale === 'B'}{else /}layui-btn-primary{/if}">B</a>
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale=C&label_id={$label_id}" class="layui-btn layui-btn-sm {if $scale === 'C'}{else /}layui-btn-primary{/if}">C</a>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">标签：</label>
                            <div class="layui-input-block">
                                <div class="layui-btn-container">
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale={$scale}" class="layui-btn layui-btn-sm {if $label_id == 0}{else /}layui-btn-primary{/if}">不限</a>
                                    {foreach $labels as $v}
                                    <a type="button" href="/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale={$scale}&label_id={$v.id}" class="layui-btn layui-btn-sm {if $label_id == $v.id}{else /}layui-btn-primary{/if}">{$v.name}</a>
                                    {/foreach}
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">关键词：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" placeholder="ID或书名" autocomplete="off" class="layui-input" value="{$keyword}">
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" type="submit">搜索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="layui-col-md12" style="min-width: 880px;">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table" lay-even>
                        <colgroup>
                            <col width="80">
                        </colgroup>
                        <thead>
                        <tr>
                            <th class="text-c">小说ID</th>
                            <th>小说名</th>
                            <th>频道类型</th>
                            <th>字数</th>
                            <th>收费章节</th>
                            <th>连载状态</th>
                            <th class="text-c">
                                是否已推<br>
                                已推链接数
                            </th>
                            <th class="text-c">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach $list as $v}
                        <tr>
                            <td class="text-c">{$v.id}</td>
                            <td>{$v.title}</td>

                            <td>{$v.freq['name']}<span lay-separator="">·</span>{$v.novel_class['name']}</td>
                            <td>{$v.number_words_text}</td>
                            <td>{$v.charging_section}</td>
                            <td>
                                {if $v.update_status != 1}
                                <div style="line-height: 30px;">
                                    <p>更新中</p>
                                    <p><i class="layui-icon layui-icon-time" style="font-style: italic;font-size: 12px;">{$v.chapter_up_time}</i></p>
                                </div>
                                {else /}
                                <div style="line-height: 30px;">
                                <p>已完结</p>
                                <p><i class="layui-icon layui-icon-time" style="font-style: italic;font-size: 12px;">{$v.chapter_up_time}</i></p>
                                </div>
                                {/if}
                            </td>

                            <td class="text-c">
                                {if $v.linkCount > 0}
                                <a href="javascript:;" style="">{$v.linkCount}</a>
                                {else /}
                                未推
                                {/if}
                            </td>
                            <td class="text-c">
                                <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" onclick="create_link('{$v.id}');">生成推广链接</a>
                            </td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                    <div id="page" style="text-align: center;"></div>
                </div>
            </div>
        </div>
    </div>

</div>

<div class="link-show" style="padding:20px;display: none;">
    <form class="layui-form layui-form-pane" action="">

        <div class="layui-form-item">
            <label class="layui-form-label">hap链接</label>
            <div class="layui-inline" style="width: 460px;">
                <input type="text" id="hap" class="layui-input" value="" readonly>
            </div>
            <div class="layui-inline">
                <button type="button" class="layui-btn link" data-type="copy1">复制</button>
            </div>
            <div class="layui-input-block">
                <div class="layui-form-mid layui-word-aux">用于广告投放，浏览器不可访问，去投放请先绑定媒体回传再使用</div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">hapjs链接</label>
            <div class="layui-inline" style="width: 460px;">
                <input type="text" id="hapjs" class="layui-input" value="" readonly>
            </div>
            <div class="layui-inline">
                <button type="button" class="layui-btn link" data-type="copy2">复制</button>
            </div>
            <div class="layui-input-block">
                <div class="layui-form-mid layui-word-aux">浏览器访问跳转App，部分机型或浏览器不可跳转，不建议用于投放</div>
            </div>
        </div>

    </form>

</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    var $;
    var admin;
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'laypage','flow'], function () {
        var laypage = layui.laypage;
        var flow = layui.flow;
        $ = layui.$;
        admin = layui.admin;

        //懒加载
        flow.lazyimg();

        laypage.render({
            elem: 'page'
            ,count: {$count}
            ,limit:{$limit}
            ,curr:{$page}
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            ,jump: function(obj,first){
                console.log(obj)
                if(!first){
                    window.location.href = '/spread/novels?freq_id={$freq.id}&class_id={$class.id}&update_status={$update_status}&words_type={$words_type}&scale={$scale}&label_id={$label_id}&page=' + obj.curr + '&limit=' + obj.limit;
                }
            }
        });

        var active = {
            copy1:function () {
                $("#hap").select(); // 选择对象
                document.execCommand("Copy"); // 执行浏览器复制命令
                layer.msg('复制成功', {icon: 1, time: 1000});
            },
            copy2:function () {
                $("#hapjs").select(); // 选择对象
                document.execCommand("Copy"); // 执行浏览器复制命令
                layer.msg('复制成功', {icon: 1, time: 1000});
            }
        }
        $('.link').on('click', function(){
            var type = $(this).data('type');
            var othis = $(this);
            active[type] ? active[type].call(this,othis) : '';
        });
    });

    function create_link(nid) {
        layer.open({
            type: 2
            ,title: '获取推广链接'
            ,offset: '15px'
            ,content: '/spread/linkInfoForm.html?novel_id='+nid+'&chapter_no=1'
            ,area: ['520px', '615px']
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
                var iframeWindow = window['layui-layer-iframe'+ index]
                    ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

                //监听提交
                iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
                    var field = data.field; //获取提交的字段
                    field.novel_id = nid;
                    //提交 Ajax 成功后，静态更新表格中的数据
                    //$.ajax({});
                    admin.req({
                        url: '/spread/createLink'
                        , type: "POST"
                        , data: field
                        , done: function (res) {
                            layer.msg('创建成功', {icon: 1, time: 1000}, function () {
                                layer.close(index); //关闭弹层
                                $("#hap").val(res.data.hap_link);
                                $("#hapjs").val(res.data.hapjs_link);
                                layer.open({
                                    type: 1,
                                    title:'链接详情',
                                    offset: '15px',
                                    area: '700px',
                                    skin: 'layui-layer-demo', //样式类名
                                    closeBtn: 0, //不显示关闭按钮
                                    anim: 2,
                                    shadeClose: true, //开启遮罩关闭
                                    content: $('.link-show')
                                });
                            });
                        },not_finish:function (res) {
                            layer.msg(res.msg);
                        }
                    });
                });
                submit.trigger('click');
            }
        });
    }
</script>
</body>